import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Layout from '../layout/IndexView.vue'
Vue.use(VueRouter)
// 从基础路由：不需要权限
export const baseRoute = [{
    path: '/',
    component: Layout,
    meta: {
      title: '首页',
      icon: 'home',
      isShowOne: true
    }, // isShowOne是否显示为顶级栏目
    children: [{
      path: '',
      name: 'home',
      component: HomeView,
      // meta:{title:'首页',icon:'home',isShowOne:true}, // 顶级栏目的meta不写在children里面
    }]
  },
  {
    path: '/401',
    component: () => import('@/views/401'),
    hidden: true
  }, {
    path: '/404',
    component: () => import('@/views/404'),
    meta: {
      title: '404'
    },
    hidden: true
  }
]
// 需要权限的路由，meta.title设置导航标题，meta.role为所需权限
export const asyncRoutes = [{
    path: '/permission',
    component: Layout,
    meta: {
      title: '权限管理',
      role: ['210', '220'],
      icon: '1',
      isShowOne: true
    }, //role:包含children的所有role
    children: [{
      path: 'index',
      name: '权限列表',
      meta: {
        title: '权限列表',
        role: ['210'],
        icon: '1'
      },
      component: () => import('../views/permission/IndexView.vue')
    }, {
      path: 'add',
      name: '添加权限',
      meta: {
        title: '添加权限',
        role: ['220'],
        icon: '1'
      },
      component: () => import('../views/permission/addView.vue')
    }]
  }, {
    path: '/nested',
    component: Layout,
    meta: {
      title: '路由嵌套',
      role: ['310', '320', '330', '331', '332'],
      icon: '2'
    },
    children: [{
      path: 'menu1',
      meta: {
        title: '菜单1',
        role: ['310'],
        icon: '2'
      },
      component: () => import('../views/nestedRouter/menu-1.vue')
    }, {
      path: 'menu2',
      meta: {
        title: '菜单2',
        role: ['320'],
        icon: '2'
      },
      component: () => import('../views/nestedRouter/menu-2.vue')
    }, {
      path: 'menu3',
      meta: {
        title: '菜单3',
        role: ['331', '332'],
        icon: '2'
      },
      redirect: '/nested/menu3/menu31',
      component: () => import('../views/nestedRouter/menu-3/menu-3.vue'), //父组件
      children: [{
        path: 'menu31',
        meta: {
          title: '菜单3-1',
          role: '331',
          icon: '2'
        },
        component: () => import('../views/nestedRouter/menu-3/menu-3-1.vue'),
      }, {
        path: 'menu32',
        meta: {
          title: '菜单3-2',
          role: ['332'],
          icon: '2'
        },
        component: () => import('../views/nestedRouter/menu-3/menu-3-2.vue'),
      }]
    }]
  }, {
    path: '/about',
    component: Layout,
    meta: {
      title: '关于',
      role: ['500'],
      icon: '3',
      isShowOne: true
    },
    children: [{
      path: '',
      name: '关于',
      component: () => import('../views/AboutView.vue'),
      // meta:{title:'关于', role:['500'],icon:'3',isShowOne:true}
    }]
    // },{
    //   path: '*',
    //   redirect:'/404',
    //   hidden:true
}]
const createRouter = () => new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: baseRoute
})

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router